Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Use the invariant culture for capitalization when generating code #2156

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

K-Tone
Copy link
Collaborator

@K-Tone K-Tone commented Mar 27, 2025

Description

A customer with the Turkish locale set, noticed that when we're generating function names for Input Actions, we're using the wrong function. This way, the "info" input action results in Onİnfo method name (notice the dot above the I, it's apparently how the capital for i looks like in Turkish).

Testing status & QA

Pending a QA pass, local testing by dev, a new regression test added

Overall Product Risks

  • Complexity: Medium
  • Halo Effect: Medium

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@ekcoh
Copy link
Collaborator

ekcoh commented Apr 2, 2025

Glanced at the draft PR and I would just like to suggest to (if possible) get some unit test in that could catch any problems with culture info.

@K-Tone
Copy link
Collaborator Author

K-Tone commented Apr 2, 2025

Also I see that some tests are failing due to compilation issues apparently, fixing that in a moment.

Copy link
Collaborator

@ritamerkl ritamerkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me. Many thanks for going through all the cases!

The PR is still a draft, so this is probably still in work, but just a changelog and a link to a Jira ticket is missing in my POV.

@K-Tone K-Tone force-pushed the anthony/ixsb-1406-fix-actions-capitalization branch from 377cefa to 96e30ba Compare April 3, 2025 14:31
@K-Tone K-Tone marked this pull request as ready for review April 8, 2025 12:16
@K-Tone
Copy link
Collaborator Author

K-Tone commented Apr 8, 2025

Moving this out of the draft stage:

  • Added a new editor regression test precisely for the user issue (Hope Håkan is ok with it)
  • Looked through the current coverage on this branch and made sure that most of the changed lines in this PR are covered by existing tests

@K-Tone K-Tone requested a review from Pauliusd01 April 8, 2025 13:41
@K-Tone K-Tone force-pushed the anthony/ixsb-1406-fix-actions-capitalization branch from 58720fc to e1de946 Compare April 9, 2025 06:01
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to get this fix in, I am approving but had some minor comments I let you decide whether they needs to be addressed or not.

@@ -66,7 +67,7 @@ private static bool IsPathInExcludedFolder(string path)
// Check if the path or any part of it contains any of the excluded folder names
foreach (string folder in excludedFolders)
{
if (path.ToLower().Contains(folder.ToLower()))
if (path.Contains(folder, StringComparison.InvariantCultureIgnoreCase))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to fix case issues here, but I wonder if this wasn't incorrect to begin with. Shouldn't this be using https://learn.microsoft.com/en-us/dotnet/api/system.io.path?view=net-9.0 which should take platform-specific behavior of underlying file systems into account instead? Its probably fine, but it is a bit of a warning flag in my eyes when code tries to "outsmart" the filesystem implementation. Its also interesting previous code was doing ToLower() on a constant that is already in lowercase (its not an arbitrary input). The point I am after is that on some OS you may have both a XR, Xr, xR and xr directory and they are all different. (e.g. linux)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for paths, we should probably use https://github.com/lucasmeijer/NiceIO because it makes pathing so easily and cool. For this instance, I would agree it might have been somewhat incorrect on case-sensitive file systems - which are normally Linux and the default Mac. Won't target changing behaviour here though.

@@ -73,10 +73,10 @@ public static void RegisterPlatform(BuildTarget target)
private static bool IsPluginInstalled()
{
var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages();
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower();
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you fixed a separate issue here right? Or are active build targets package names ToUpper? I am confused around how this previously was supposed to work. The new code looks solid though, effectively ignoring case.

}

public static bool operator==(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) == 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: One could call the other operator, e.g. return (b == a) to avoid the redundant code

}

public static bool operator!=(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) != 0;
return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) != 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: One could call the other operator, e.g. return (b != a)

@K-Tone K-Tone force-pushed the anthony/ixsb-1406-fix-actions-capitalization branch from 21c0680 to ee83350 Compare April 10, 2025 10:28
@Pauliusd01
Copy link
Collaborator

Did not forget about this one, will check today/tomorrow

Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I checked generating and using input actions with non latin characters (Chinese, Russian, Japanese, Arabic, Hebrew, Korean, Thai, Vietnamese, Turkish) on Windows and Mac with Chinese, English and Turkish locales.

But I have to note that I wasn't able to repro the original turkish i character issue on my end. The latin letters i and I stayed the same after generating them on a different locale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants